package com.itheima.consumer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: fanYuLe
 * @CreateTime: 2025-03-24  13:58
 * @Description:
 */
@Configuration
public class DirectConfig {

    /**
     * 声明交换机
     *
     */
    @Bean
    public DirectExchange directExchange(){
        return ExchangeBuilder.directExchange("hmall.direct").build();
    }
    /**
     * 第一个队列
     */
    @Bean
    public Queue directQueue1(){
        return new Queue("direct.queue1");
    }
    /**
     * 绑定队列1和交换机 routingKey为red
     */
    @Bean
    public Binding bindingQueue1WithRed(Queue directQueue1,DirectExchange directExchange ){
        return BindingBuilder.bind(directQueue1).to(directExchange).with("red");
    }


    /**
     * 绑定队列1和交换机 routingKey为blue
     */
    @Bean
    public Binding bindingQueue1WithBlue(Queue directQueue1,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue1).to(directExchange).with("blue");
    }

    /**
     * 第二个队列
     */
    @Bean
    public Queue directQueue2(){
        return new Queue("direct.queue2");
    }

    /**
     * 绑定队列2和交换机 red
     */
    @Bean
    public Binding bindingDirectQueue2WithRed(Queue directQueue2,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue2).to(directExchange).with("red");
    }

    /**
     * 绑定队列2和交换机 yellow
     */
    @Bean
    public Binding bindingDirectQueue2WithYellow(Queue directQueue2,DirectExchange directExchange){
        return BindingBuilder.bind(directQueue2).to(directExchange).with("yellow");
    }




}
